package com.cyzy.mq;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.cyzy.controller.EmailController;
import com.cyzy.pojo.Email;
import com.cyzy.service.EmailService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component
@RocketMQMessageListener(topic = "emil-topic", consumerGroup = "consumer-email")
public class MQConsumer implements RocketMQListener<String> {

    @Autowired
    private EmailService emailService;

    @Override
    public void onMessage(String s) {  // 有消息自动调用onMessage
        System.out.println("接收到消息:"+s);
        Email email = JSON.parseObject(s, Email.class);
        System.out.println(email);

        int templateId = email.getTemplateId();
        if(templateId == 1){
            emailService.emailLogin(email.getTo(), templateId, email.getUserName(), email.getCode());
        }else if(templateId == 2){

        }
    }
}
